From 09353d0ed60162633c028d55c8df3f74cc0c6bea Mon Sep 17 00:00:00 2001 From: Thien-Thi Nguyen Date: Sun, 30 Jul 2006 20:19:36 +0000 Subject: [PATCH] (url-hexify-string): Rewrite. --- lisp/url/url-util.el | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el index f33a58950fc..4293b0e301f 100644 --- a/lisp/url/url-util.el +++ b/lisp/url/url-util.el @@ -352,17 +352,18 @@ forbidden in URL encoding." This is taken from RFC 2396.") ;;;###autoload -(defun url-hexify-string (str) - "Escape characters in a string." - (mapconcat - (lambda (char) - ;; Fixme: use a char table instead. - (if (not (memq char url-unreserved-chars)) - (if (> char 255) - (error "Hexifying multibyte character %s" str) - (format "%%%02X" char)) - (char-to-string char))) - str "")) +(defun url-hexify-string (string) + "Return a new string that is STRING URI-encoded. +First, STRING is converted to utf-8, if necessary. Then, for each +character in the utf-8 string, those found in `url-unreserved-chars' +are left as-is, all others are represented as a three-character +string: \"%\" followed by two lowercase hex digits." + (mapconcat (lambda (char) + (if (memq char url-unreserved-chars) + (char-to-string char) + (format "%%%02x" char))) + (encode-coding-string string 'utf-8 t) + "")) ;;;###autoload (defun url-file-extension (fname &optional x) -- 2.30.2